//
//  UIButton+Additions.swift
//  MGExtensionsKit
//
//  Created by Max's mini on 2019/12/4.
//

import Foundation
import Kingfisher

public extension UIButton {
    func setImage(urlString: String,
                      for state: UIControl.State,
                      placeholder: UIImage? = nil,
                      options: KingfisherOptionsInfo? = nil,
                      progressBlock: DownloadProgressBlock? = nil,
                      completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) {
        let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? urlString)
        kf.setImage(with: url, for: state, placeholder: placeholder, options: options, progressBlock: progressBlock, completionHandler: completionHandler)
    }
}


extension Extensive where Base: UIButton {
    
    public func setBackgroundImageColor(_ color: UIColor, for state: UIControl.State) {
        let image = UIImage.mg.imageWithColor(color)
        base.setBackgroundImage(image, for: state)
    }
    
}
